package com.starview.star.code.repository;

import com.starview.platform.data.value.ResourceURI;
import com.starview.star.compiler.util.PrettyPrintDisplay;

/**
 * A node in the code repository
 * 
 * @author fgm
 * 
 */
@SuppressWarnings("serial")
public class RepositoryNodeImpl implements RepositoryNode
{
  protected String hash;
  private CodeCatalog code;
  private final ResourceURI uri;

  public RepositoryNodeImpl(ResourceURI uri, String hash, CodeCatalog code)
  {
    this.uri = uri;
    this.hash = hash;
    this.code = code;
  }

  @Override
  public CodeCatalog getCode()
  {
    return code;
  }

  @Override
  public ResourceURI getUri()
  {
    return uri;
  }

  @Override
  public String getHash()
  {
    return hash;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    if (hash != null)
      disp.appendQuoted(hash);
    else
      disp.append("??");
    disp.append("->");
    code.prettyPrint(disp);
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }

}
